package com.aspose.cells;

import java.util.HashMap;

class zadw {
   private zaeh a = null;

   zadw(zaeh var1) {
      this.a = var1;
   }

   void a(zafg var1, String var2, String var3, String var4, String var5, boolean var6) throws Exception {
      zaty var7 = new zaty();
      var7.a(this.a.g.getWorksheets());
      int var8 = var7.size();
      if (var8 != 0) {
         this.a.a(new HashMap(var8));
         if (!var6) {
            this.a.b(new HashMap(var8));
         }

         int var9 = 0;

         for(int var10 = 0; var10 < var8; ++var10) {
            zatx var11 = var7.a(var10);
            if (var11.a() != null) {
               if (this.a.c().getExportHiddenWorksheet()) {
                  if (this.a.r.size() == 1) {
                     boolean var12 = false;
                     Worksheet var13 = (Worksheet)this.a.r.get(0);
                     int var14;
                     int var15;
                     if (var13.i() != null) {
                        var14 = var13.i().getCount();

                        for(var15 = 0; var15 < var14; ++var15) {
                           Picture var16 = var13.getPictures().get(var15);
                           if (var16.b() == var10 + 1 && !zaff.a(var16)) {
                              var12 = true;
                              break;
                           }
                        }
                     }

                     if (var13.k() != null) {
                        var14 = var13.k().getCount();

                        for(var15 = 0; var15 < var14; ++var15) {
                           OleObject var31 = var13.getOleObjects().get(var15);
                           if (var31.e() == var10 + 1) {
                              var12 = true;
                              break;
                           }
                        }
                     }

                     if (!var12) {
                        continue;
                     }
                  }
               } else if (!this.a(var10)) {
                  continue;
               }

               if (var11.a) {
                  String var26 = "image" + zaff.a(var9, 3) + ".pict";
                  ++var9;
                  this.a.f().put(var10, this.a.b(var2) + var26);
                  if (this.a.c().getExportImagesAsBase64() && var1 == null) {
                     return;
                  }

                  if (var1 == null) {
                     if (!var6) {
                        StreamProviderOptions var28 = new StreamProviderOptions();
                        var28.a = this.a.o + "/" + var26;
                        this.a.u.initStream(var28);
                        if (var28.b != null) {
                           this.a.g().put(var10, var28.b);
                        }

                        com.aspose.cells.b.a.d.zm var29 = var28.c;
                        var29.b(var11.a(), 0, var11.a().length);
                        this.a.u.closeStream(var28);
                     }
                  } else if (var6) {
                     this.a(var1, var2, var3 + var26, var4, var11.a(), var5);
                  }
               } else {
                  ImageFormat var23 = var11.b();
                  byte[] var24 = var11.a();
                  if (var23 == ImageFormat.getPng()) {
                     try {
                        com.aspose.cells.a.d.zfg var25 = new com.aspose.cells.a.d.zfg();
                        var25.a(new com.aspose.cells.b.a.d.zh(var24));
                        byte[] var30 = var25.d();
                        if (var30 != null) {
                           var24 = var30;
                           var23 = ImageFormat.getGif();
                        }
                     } catch (Exception var21) {
                        ;
                     }
                  }

                  String var27 = zase.a(var23);
                  if (var27 == null) {
                     var27 = ".jpg";
                     var23 = ImageFormat.getJpeg();
                  }

                  String var32 = "image" + zaff.a(var9, 3) + var27;
                  ++var9;
                  this.a.f().put(var10, this.a.b(var2) + var32);
                  if (!this.a.c().getExportImagesAsBase64() || var1 != null) {
                     (new StringBuilder()).append(this.a.n).append(var32).toString();

                     StreamProviderOptions var19;
                     com.aspose.cells.b.a.d.zm var20;
                     try {
                        com.aspose.cells.b.a.d.zh var18 = new com.aspose.cells.b.a.d.zh(var24);
                        com.aspose.cells.b.a.b.za var17 = new com.aspose.cells.b.a.b.za(var18);
                        if (var17 != null) {
                           if (var23 == ImageFormat.getJpeg()) {
                              var17 = com.aspose.cells.a.d.zbn.a((com.aspose.cells.b.a.b.za)var17, 1);
                           }

                           if (var1 == null) {
                              if (!var6) {
                                 var19 = new StreamProviderOptions();
                                 var19.a = this.a.o + "/" + var32;
                                 this.a.u.initStream(var19);
                                 if (var19.b != null) {
                                    this.a.g().put(var10, var19.b);
                                 }

                                 var20 = var19.c;
                                 var20.b(var24, 0, var24.length);
                                 this.a.u.closeStream(var19);
                              }
                           } else if (var6) {
                              this.a(var1, var2, var3 + var32, var4, var24, var5);
                           }
                        }
                     } catch (Exception var22) {
                        if (var1 == null) {
                           if (!var6) {
                              var19 = new StreamProviderOptions();
                              var19.a = this.a.o + "/" + var32;
                              this.a.u.initStream(var19);
                              if (var19.b != null) {
                                 this.a.g().put(var10, var19.b);
                              }

                              var20 = var19.c;
                              var20.b(var24, 0, var24.length);
                              this.a.u.closeStream(var19);
                           }
                        } else if (var6) {
                           this.a(var1, var2, var3 + var32, var4, var24, var5);
                        }
                     }
                  }
               }
            }
         }

      }
   }

   private boolean a(int var1) {
      for(int var2 = 0; var2 < this.a.r.size(); ++var2) {
         Worksheet var3 = (Worksheet)this.a.r.get(var2);
         if (var3.isVisible() && var3.i() != null) {
            int var4 = var3.i().getCount();

            for(int var5 = 0; var5 < var4; ++var5) {
               Picture var6 = var3.getPictures().get(var5);
               if (var6.b() == var1 + 1) {
                  return true;
               }
            }
         }
      }

      return false;
   }

   private void a(zafg var1, String var2, String var3, String var4, byte[] var5, String var6) throws Exception {
      zaeh.b(var1, var2, var3, var4, var6);
      var1.a(com.aspose.cells.b.a.ze.a(var5));
   }
}
